/*
* @Author: sam
* @Date:   2017-10-11 18:02:49
* @Last Modified by:   sam
* @Last Modified time: 2017-10-25 10:40:56
*/
(function(win){
	var TipBox = function(id){
		this.init.call(this,id);
	};
	TipBox.prototype = {
		init : function(id){//初始化
			this.id = id;
			this.domSelector = {
				'tipTitle' : '.tipTitle span.areaName',
				'tipMsg' : '.tipMsg div',
				'contact' : '.contact a',
				'address' : '.address a',
				'detail' : '.detail a',
				'detailBox' : '.detail',
				'tipAction' : '.tipAction',
				'enter' : '.enter'
			};
			this.dom = document.getElementById(this.id);
			this.getDom();
			return this;
		},
		getDom : function(){
			this.doms = {};
			for(var key in this.domSelector){
				this.doms[key] = this.dom.querySelector(this.domSelector[key]);
			}
		},
		show : function(){
			if(!this.dom.classList.contains('active')){
				this.dom.classList.add('active');
			}
		},
		hide : function(){
			if(this.dom.classList.contains('active')){
				this.dom.classList.remove('active');
			}
		},
		changeContent : function(obj){
			var that = this;
			var statusText = {
				'shi' : '查看下属县',
				'xian' : '查看下属乡镇',
				'zhen' : '查看下属村'
			};
			if(obj['status'] === "cun" || obj['status'] === "one"){
				this.hide();
			}else{
				this.hide();
				return false;
			}
			window.setTimeout(function(){
				for(var key in obj){
					if(key === "tipTitle" || key === "tipMsg"){
						that.doms[key].innerHTML = obj[key];
					}
					if(key === "contact"){
						that.doms[key].href = "javascript:;";
					}
					if(key === "address"){
						that.doms[key].href = "javascript:;";
					}
				}
				if(obj['contact'] === "" && obj['address'] === ""){
					that.doms['tipAction'].style.display = 'none';
				}else{
					that.doms['tipAction'].style.display = 'block';
				}

				//显示进入下一层按钮
				// if(statusText[obj['status']] !== undefined){
				// 	that.doms['enter'].style.display = "block";
				// 	that.doms['enter'].innerHTML = statusText[obj['status']];
				// 	that.doms['enter'].onclick = function(e){
				// 		obj['fn']();
				// 	}
				// }else{
				// 	that.doms['enter'].style.display = "none";
				// }

				if(obj['status'] === "cun"){
					that.doms['detailBox'].style.display = 'block';
					that.doms['tipAction'].style.display = 'none';
					that.doms['detail'].href = './list.html?code=' + obj['code'];
				}else if(obj['status'] === "one"){
					that.doms['detailBox'].style.display = 'block';
					that.doms['tipAction'].style.display = 'block';
					that.doms['detail'].href = './detail.html?code=' + obj['code'];
				}else{
					that.doms['detailBox'].style.display = 'none';
					that.doms['tipAction'].style.display = 'none';
				}

				//显示是否显示详情按钮

				that.doms['contact'].setAttribute('tel', obj['contact']);
				that.doms['contact'].onclick = function(e){
					makeCall(e.target);
				}

				that.doms['address'].setAttribute('dest_name', obj['tipTitle']);
				that.doms['address'].setAttribute('lng', obj['lng']);
				that.doms['address'].setAttribute('lat', obj['lat']);
				that.doms['address'].onclick = function(e){
					openApp(e.target);
				};
				if(obj['status'] === "cun" || obj['status'] === "one"){
					that.show();
				}
			},1000);
		}
	};
	win.Class = win.Class || {};
	win.Class.TipBox = TipBox;
})(window);